#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    vector<int> f(n + 1, 1), g(n + 1, 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < i; j++) {
            if (arr[i] > arr[j]) {
                f[i] = max(f[i], f[j] + 1);
            }
        }
    }
    for (int i = n; i >= 1; i--) {
        for (int j = n; j > i; j--) {
            if (arr[i] > arr[j]) {
                g[i] = max(g[i], g[j] + 1);
            }
        }
    }
    int ret = 0;
    for (int i = 1; i <= n; i++) {
        ret = max(ret, f[i] + g[i] - 1);
    }

    cout << n - ret << endl;
    return 0;
}
